#!/bin/bash
#PASSWD='Hlwfy#$2021!'

sshcreate(){
for IP in $( cat /root/works/arm-k8s/ip-list )
do
     ping -c 2 $IP
     if [ $? -eq 0 ]; then
     expect -c "set timeout -1;
     spawn /usr/bin/ssh-copy-id -i /root/.ssh/id_rsa.pub root@$IP;
         expect {
                *yes/no* {send -- yes\r;exp_continue;}
                *password:* {send -- Admin\@9000\r;exp_continue;}
          eof    {exit 0}
                }";
     else
          exit
     fi
Done
}

sshlink(){
for IP in $( cat /root/works/arm-k8s/ip-list )
do
     ping -c 2 $IP
     if [ $? -eq 0 ]; then
     expect -c "set timeout -1;
     spawn ssh root@$IP exit;
         expect {
                *yes/no* {send -- yes\r;exp_continue;}
          eof    {exit 0}
                }";
     else
          exit
     fi
done
}

sshcreate
sshlink
